package com.suixun.controller.credits;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.authority.controller.BaseManager;
import com.suixun.service.credits.CompanyUserService;
import com.suixun.util.Constant;
import com.suixun.util.Utils;

/**
 * 商家登陆账号
 * 
 * @author yh
 * @date 2017年12月7日
 */
@RestController
@RequestMapping(value = "/credits/company/user")
public class CompanyUserController extends BaseManager {

    @Autowired
    private CompanyUserService companyUserService;

    /**
     * 验证账号是可用
     * 
     * @param account
     * @param companyid
     *            不为空则是修改时校验
     * @return
     */
    @RequestMapping(value = "/verify_account.json")
    public Object verifyAccount(@RequestParam(value = "account") String account,
                                @RequestParam(value = "companyid", required = false) Integer companyid) {

        /*if (!checkRight()) {
            return fail(Constant.Authority.CHECK_FALSE);
        }*/

        try {
            if (StringUtils.isEmpty(account) || !Utils.isTel(account)) {
                return fail(Constant.PARAM_ERROR);
            }
            boolean bool = companyUserService.verifyAccount(account, companyid);
            return success(bool);
        } catch (Exception e) {
            logger("CompanyUserController verifyAccount:" + e.getMessage(), e);
            return fail(Constant.EXCEPTION.OPERATE_FAIL);
        }
    }

}
